package com.bestcem.xm.user.dao.impl;

import com.bestcem.xm.user.dao.UserBookingTrackDao;
import com.bestcem.xm.user.dao.mapper.UserBookingTrackMapper;
import com.bestcem.xm.user.entity.mysql.UserBookingTrack;
import com.bestcem.xm.user.entity.pojo.UserBookingTrackDO;
import com.bestcem.xm.user.util.business.DataBaseUtil;
import com.bestcem.xm.user.util.convert.UserBookingTrackConvert;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 用户埋点数据服务
 *
 * @author qiongyu.cui <qiongyu.cui@idiaoyan.com>
 * @version v1.0
 * @date 2022/3/17 16:31
 */
@Repository
public class UserBookingTrackDaoImpl implements UserBookingTrackDao {

    @Resource
    private UserBookingTrackMapper userBookingTrackMapper;

    @Resource
    private UserBookingTrackConvert userBookingTrackConvert;

    @Override
    public String insert(UserBookingTrackDO userBookingTrackDO) {
        UserBookingTrack userBookingTrack = userBookingTrackConvert.do2Mysql(userBookingTrackDO);
        DataBaseUtil.setCreateAndUpdateTime(userBookingTrack);
        userBookingTrack.setBookingtrackId(DataBaseUtil.generateId());
        userBookingTrackMapper.insert(userBookingTrack);
        return userBookingTrack.getBookingtrackId();
    }

    @Override
    public String insertSelective(UserBookingTrackDO userBookingTrackDO) {
        UserBookingTrack userBookingTrack = userBookingTrackConvert.do2Mysql(userBookingTrackDO);
        DataBaseUtil.setCreateAndUpdateTime(userBookingTrack);
        userBookingTrack.setBookingtrackId(DataBaseUtil.generateId());
        userBookingTrackMapper.insertSelective(userBookingTrack);
        return userBookingTrack.getBookingtrackId();
    }

    @Override
    public UserBookingTrackDO selectById(String bookingTrackId) {
        return userBookingTrackConvert.mysql2Do(userBookingTrackMapper.selectByPrimaryKey(bookingTrackId));
    }

    @Override
    public Integer updateSelectiveById(UserBookingTrackDO userBookingTrackDO) {
        UserBookingTrack userBookingTrack = userBookingTrackConvert.do2Mysql(userBookingTrackDO);
        DataBaseUtil.setUpdateTime(userBookingTrack);
        return userBookingTrackMapper.updateByPrimaryKeySelective(userBookingTrack);
    }

    @Override
    public Integer updateSelectiveByOrgCode(UserBookingTrackDO userBookingTrackDO) {
        UserBookingTrack userBookingTrack = userBookingTrackConvert.do2Mysql(userBookingTrackDO);
        DataBaseUtil.setUpdateTime(userBookingTrack);
        return userBookingTrackMapper.updateSelectiveByOrgCode(userBookingTrack);
    }

    @Override
    public List<UserBookingTrackDO> selectBySelective(UserBookingTrackDO userBookingTrackDO) {
        return userBookingTrackConvert.mysqls2Dos(userBookingTrackMapper.selectBySelective(userBookingTrackConvert.do2Mysql(userBookingTrackDO)));
    }

    @Override
    public List<UserBookingTrackDO> selectByCreateTimeInterval(Date startTime, Date endTime) {
        return userBookingTrackConvert.mysqls2Dos(userBookingTrackMapper.selectByCreateTimeInterval(startTime, endTime));
    }

}
